<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
		<title>Gears Sample - module Database </title>
		<script type="text/javascript" src="gears_init.js"></script>
		<script type="text/javascript">
			function init() {
				if (!window.google || !google.gears) {
					alert("Install Gears");
				}
				var permission = google.gears.factory.getPermission("WebDb by Q", "../images/webdb.png");
				if (!permission) {
					alert("No permission");
				}
				var name = prompt("What is your name?", "");
				var db = google.gears.factory.create('beta.database');
				db.open('database-test');
				db.execute('create table if not exists Names (Name TEXT, Timestamp INTEGER)');
				db.execute('insert into Names values (?, ?)', [name, new Date().getTime()]);
				var rs = db.execute('select Name, Timestamp from Names order by Timestamp desc');
				var result = "";
				while (rs.isValidRow()) {
					result += rs.fieldName(0) + " = " + rs.field(0) + ", "
							+ rs.fieldName(1) + " = " + new Date(rs.field(1)) + "<br>";
					rs.next();
				}
				if (rs) {
					rs.close();
				}
				var out = document.getElementById("output");
				out.innerHTML = result;
			}
		</script>
	</head>
	<body onload="init()">
		<div id="output"></div>
	</body>
</html>
